import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

public class RedisDemoString {
    public static void test1(Jedis jedis) {
        System.out.println("mget mset");
        jedis.flushAll();

        jedis.mset("key1","111", "key2","222", "key3", "333", "key4","444");
        List<String> list = jedis.mget("key1", "key2","key5", "key3", "key4");
        System.out.println(list);
    }

    public static void test2(Jedis jedis) {
        System.out.println("getrange 和 setrange");
        jedis.flushAll();

        jedis.set("key", "abcdefghijk");
        jedis.setrange("key", 4, "wwwww");
        String key = jedis.getrange("key", 3, 7);
        System.out.println(key);
    }

    public static void test3(Jedis jedis) {
        System.out.println("append");
        jedis.flushAll();

        jedis.set("key","abcde");
        jedis.append("key","www");
        String s = jedis.get("key");
        System.out.println(s);

    }

    public static void test4(Jedis jedis) {
        System.out.println("incr decr");
        jedis.flushAll();

        jedis.set("key","666");
        jedis.incr("key");
        String s = jedis.get("key");
        System.out.println(s);

        jedis.decr("key");
        s = jedis.get("key");
        System.out.println(s);

        jedis.incrBy("key", 123);
        s = jedis.get("key");
        System.out.println(s);

        jedis.decrBy("key",123);
        s = jedis.get("key");
        System.out.println(s);
    }
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
        try(Jedis jedis = jedisPool.getResource()) {
            test4(jedis);
        }
    }
}
